//
//  ClubDetailViewController.m
//  PaiQuan
//
//  Created by Mac on 16/7/14.
//  Copyright © 2016年 huigu. All rights reserved.
//

#import "ClubDetailViewController.h"
#import "PersonalViewController.h"
#import "ClubViewController.h"
#import "ClubSettingController.h"
@interface ClubDetailViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UIAlertViewDelegate,UIScrollViewDelegate>
//头部试图
@property(nonatomic,strong)UIScrollView *scrollView;

@property(nonatomic,strong)UIView *headerView;
//头像
@property(nonatomic,strong)UIImageView *headerImgView;
//名字
@property(nonatomic,strong)UILabel *nameLabel;
//工会地址
@property(nonatomic,strong)UILabel *addressLabel;
//工会介绍
@property(nonatomic,strong)UILabel *introductionLabel;
//会长view
@property(nonatomic,strong)UIView *chairmanView;
//会长label
@property(nonatomic,strong)UILabel *chairmanLabel;
//会长头像
@property(nonatomic,strong)UIImageView *chairManImgView;
//会长昵称
@property(nonatomic,strong)UILabel *chairmanNicknameLabel;
//俱乐部的view
@property(nonatomic,strong)UIView *clubView;
//俱乐部号
@property(nonatomic,strong)UILabel *clubNumLabel;

@property(nonatomic,strong)UILabel *clubNumber;
//会员
@property(nonatomic,strong)UILabel *associatorLabel;
//会员列表
@property(nonatomic,strong)UICollectionView *associatorCollectionView;
//message免打扰
@property(nonatomic,strong)UIView *aestivateView;

@property(nonatomic,strong)UILabel *aestivateLabel;
//uiswitch开关
@property(nonatomic,strong)UISwitch *messageSwitch;

//clear
@property(nonatomic,strong)UIView *clearView;
@property(nonatomic,strong)UILabel *clearLabel;
//创建时间
@property(nonatomic,strong)UILabel *buildDateLabel;

@property(nonatomic,strong)UIView *coverView;
@end
static NSString *CellID = @"cellID";
@implementation ClubDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   
    self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, ScreenW, ScreenH)];
    
    self.scrollView.backgroundColor = PQ_COLOR_LightGray;
    self.scrollView.contentSize = CGSizeMake(ScreenW, ScreenH+RATIO(100));
    self.scrollView.bounces = YES;
    self.scrollView.scrollEnabled = YES;
    // 是否分页
    self.scrollView.pagingEnabled = NO;
    // 是否滚动
    self.scrollView.delegate = self;
   
     self.scrollView.showsVerticalScrollIndicator = NO;
    [self.view addSubview:self.scrollView];

    self.titleView.title = @"俱乐部详情";
    [self.titleView.btnBack setImage:PQIMG(@"back") forState:UIControlStateNormal];
    [self.titleView.btnBack setTitle:@"返回" forState:UIControlStateNormal];
    [self.titleView.btnBack setTitleColor:PQ_COLOR_YELLOW forState:UIControlStateNormal];
    
    [self.titleView.rightBtn setTitle:@"退出" forState:UIControlStateNormal];
    [self.titleView.rightBtn setTitleColor:PQ_COLOR_YELLOW forState:UIControlStateNormal];
    [self.titleView.rightBtn addTarget:self action:@selector(rightBtnDidClick) forControlEvents:UIControlEventTouchUpInside];
    
    [self setUPUI];
    [self setUPCon];

    
}
-(void)setUPUI{
    [self.scrollView addSubview:self.headerView];
    [self.headerView addSubview:self.headerImgView];
    [self.headerView addSubview:self.nameLabel];
    [self.headerView addSubview:self.addressLabel];
    [self.headerView addSubview:self.introductionLabel];
    [self.scrollView addSubview:self.chairmanView];
    [self.chairmanView addSubview:self.chairmanLabel];
    [self.chairmanView addSubview:self.chairManImgView];
    [self.chairmanView addSubview:self.chairmanNicknameLabel];
    [self.scrollView addSubview:self.clubView];
    [self.clubView addSubview:self.clubNumLabel];
    [self.clubView addSubview:self.clubNumber];
    [self.scrollView addSubview:self.associatorLabel];
    [self.scrollView addSubview:self.associatorCollectionView];
    [self.scrollView addSubview:self.aestivateView];
    [self.aestivateView addSubview:self.aestivateLabel];
    [self.aestivateView addSubview:self.messageSwitch];
    [self.scrollView addSubview:self.clearView];
    [self.clearView addSubview:self.clearLabel];
    [self.scrollView addSubview:self.buildDateLabel];

}
-(void)setUPCon{
    [self.headerView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.scrollView.top).offset(RATIO(NaviBarHeight)+RATIO(42));
        make.width.equalTo(self.scrollView.width);
        make.height.equalTo(RATIO(300));
        make.left.equalTo(self.scrollView.left);
        
        
    }];
    [self.headerImgView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.headerView.top).offset(RATIO(22));
        make.centerX.equalTo(self.headerView.centerX);
        make.width.height.equalTo(RATIO(120));
        
        
    }];
    [self.nameLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.headerView.top).offset(RATIO(164));
        make.width.equalTo(self.headerView.width);
        make.centerX.equalTo(self.headerView);
        
        
    }];
    [self.addressLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.headerView.top).offset(RATIO(214));
        make.width.equalTo(self.headerView.width);
        make.centerX.equalTo(self.headerView);
    }];
    [self.introductionLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.headerView.top).offset(RATIO(257));
        make.width.equalTo(self.headerView.width);
        make.centerX.equalTo(self.headerView);
    }];
    [self.chairmanView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.headerView.bottom).offset(RATIO(24));
        make.centerX.equalTo(self.headerView);
        make.width.equalTo(self.headerView);
        make.height.equalTo(RATIO(96));
    }];
    [self.chairmanLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.chairmanView.left).offset(RATIO(20));
        make.centerY.equalTo(self.chairmanView);
    }];
    [self.chairManImgView makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.chairmanView.left).offset(RATIO(198));
        make.centerY.equalTo(self.chairmanView.centerY);
        make.width.height.equalTo(RATIO(70));
    }];
    [self.chairmanNicknameLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.chairManImgView.right).offset(RATIO(20));
        make.centerY.equalTo(self.chairManImgView);
    }];
    [self.clubView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.chairmanView.bottom).offset(RATIO(4));
        make.left.equalTo(self.scrollView.left);
        make.width.equalTo(self.scrollView.width);
        make.height.equalTo(RATIO(96));
    }];
    [self.clubNumLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.clubView.left).offset(RATIO(20));
        make.centerY.equalTo(self.clubView);
    }];
    [self.clubNumber makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.clubView);
         make.left.equalTo(self.clubView.left).offset(RATIO(198));

    }];
    [self.associatorLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.scrollView.left).offset(RATIO(20));
        make.top.equalTo(self.clubView.bottom);
        make.height.equalTo(RATIO(60));
        
        
    }];
    [self.associatorCollectionView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.associatorLabel.bottom);
        make.width.equalTo(self.scrollView.width);
        make.height.equalTo(RATIO(145));
        make.left.equalTo(self.scrollView.left);
        
    }];
    [self.aestivateView makeConstraints:^(MASConstraintMaker *make) {
         make.top.equalTo(self.associatorCollectionView.bottom).offset(RATIO(24));
        make.left.equalTo(self.scrollView.left);
        make.height.equalTo(RATIO(96));
        make.width.equalTo(self.scrollView.width);

    }];
    [self.aestivateLabel makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.aestivateView);
        make.left.equalTo(self.aestivateView.left).offset(RATIO(20));

    }];
    [self.messageSwitch makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.aestivateView.right).offset(-RATIO(20));
        make.centerY.equalTo(self.aestivateView);
    }];
    [self.clearView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.aestivateView.bottom).offset(RATIO(4));
        make.left.equalTo(self.scrollView.left);
        make.height.equalTo(RATIO(96));
        make.width.equalTo(self.scrollView.width);


    }];
    [self.clearLabel makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.clearView);
        make.left.equalTo(self.clearView.left).offset(RATIO(20));
        
    }];
    [self.buildDateLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.clearView.bottom).offset(RATIO(24));
        make.centerX.equalTo(self.scrollView);
    }];
    
}
#pragma mark --colletionn数据源方法
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 8;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellID forIndexPath:indexPath];
    cell.backgroundColor = [UIColor whiteColor];
    for(id subView in cell.contentView.subviews){
        [subView removeFromSuperview];
    }
    UIImageView *imgView =[[UIImageView alloc] init];
    imgView.frame = CGRectMake(0, 0, RATIO(100), RATIO(100));
    imgView.backgroundColor = PQ_COLOR_DarkGray;
    imgView.layer.cornerRadius = RATIO(100)/2.0f;
    imgView.layer.masksToBounds = YES;
    
    [cell addSubview:imgView];
    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
  
}
#pragma mark --按钮的点击事件
-(void)rightBtnDidClick{
    UIWindow *windowView = [UIApplication sharedApplication].keyWindow;
    self.coverView = [[UIView alloc] init];
    self.coverView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.7];
    self.coverView.frame = CGRectMake(0, 0, ScreenW, ScreenH);
    [windowView addSubview:self.coverView];

   
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"退出公会" message:@"确定退出该俱乐部?若退出一周内不得重复加入该俱乐部" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    [alertView show];
  
    
    
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
     [self.coverView removeFromSuperview];
    if (buttonIndex == 0) {
        
        [alertView removeFromSuperview];
    }else{
        [self.navigationController popToRootViewControllerAnimated:YES];
    }
    
    
}
-(void)headViewDidClick{
    NSLog(@"点击了");
    ClubSettingController *settingVC = [[ClubSettingController alloc] init];
    [self.navigationController pushViewController:settingVC animated:YES];
    
}



-(void)chairmanDidClick{
    PersonalViewController *personVC =[[PersonalViewController alloc] init];
    [self.navigationController pushViewController:personVC animated:YES];
}
#pragma mark --懒加载
-(UIView *)headerView{
    if (!_headerView) {
        _headerView = [[UIView alloc] init];
        _headerView.backgroundColor = PQ_COLOR_DarkGray;
        UITapGestureRecognizer *gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(headViewDidClick)];
        [_headerView addGestureRecognizer:gesture];
    }
    
    return _headerView;
}
-(UIImageView*)headerImgView{
    if (!_headerImgView) {
        _headerImgView = [[UIImageView alloc] init];
        _headerImgView.backgroundColor = [UIColor whiteColor];
        _headerImgView.layer.cornerRadius = RATIO(120)/2.0f;
        _headerImgView.layer.masksToBounds = YES;
    }
    
    return _headerImgView;
}
-(UILabel *)nameLabel{
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc] init];
        [_nameLabel  setText:@"帕丽斯的苹果"];
        [_nameLabel setTextColor:[UIColor whiteColor]];
        [_nameLabel setFont:FONT(16)];
        _nameLabel.textAlignment = NSTextAlignmentCenter;
    }
    
    return _nameLabel;
}
-(UILabel *)addressLabel{
    if (!_addressLabel) {
        _addressLabel = [[UILabel alloc] init];
        [_addressLabel  setText:@"浙江 温州"];
        [_addressLabel setTextColor:[UIColor whiteColor]];
        [_addressLabel setFont:FONT(12)];
        _addressLabel.textAlignment = NSTextAlignmentCenter;
    }
    
    return _addressLabel;
}
-(UILabel *)introductionLabel{
    if (!_introductionLabel) {
        _introductionLabel = [[UILabel alloc] init];
        [_introductionLabel  setText:@"咱们公会就是牛逼么"];
        [_introductionLabel setTextColor:[UIColor whiteColor]];
        [_introductionLabel setFont:FONT(12)];
        _introductionLabel.textAlignment = NSTextAlignmentCenter;
    }
    
    return _introductionLabel;
}
-(UIView *)chairmanView{
    if (!_chairmanView) {
        _chairmanView = [[UIView alloc] init];
        _chairmanView.backgroundColor = [UIColor whiteColor];
        UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(chairmanDidClick)];
        [_chairmanView addGestureRecognizer:tapGesture];
    
      
    }
    
    return _chairmanView;
}
-(UILabel *)chairmanLabel{
    if (!_chairmanLabel) {
        _chairmanLabel = [[UILabel alloc] init];
        [_chairmanLabel  setText:@"会长"];
        [_chairmanLabel setTextColor:[UIColor blackColor]];
        [_chairmanLabel setFont:FONT(16)];
        _chairmanLabel.textAlignment = NSTextAlignmentLeft;
    }
    
    return _chairmanLabel;
}
-(UIImageView*)chairManImgView{
    if (!_chairManImgView) {
        _chairManImgView = [[UIImageView alloc] init];
        _chairManImgView.backgroundColor = PQ_COLOR_SimpleGary;
        _chairManImgView.layer.cornerRadius = RATIO(70)/2.0f;
        _chairManImgView.layer.masksToBounds = YES;
    }
    
    return _chairManImgView;
}
-(UILabel *)chairmanNicknameLabel{
    if (!_chairmanNicknameLabel) {
        _chairmanNicknameLabel = [[UILabel alloc] init];
        [_chairmanNicknameLabel  setText:@"隐匿偷窥者"];
        [_chairmanNicknameLabel setTextColor:PQ_COLOR_SimpleGary];
        [_chairmanNicknameLabel setFont:FONT(14)];
        _chairmanNicknameLabel.textAlignment = NSTextAlignmentLeft;
    }
    
    return _chairmanNicknameLabel;
}
-(UIView *)clubView{
    if (!_clubView) {
        _clubView = [[UIView alloc] init];
        _clubView.backgroundColor = [UIColor whiteColor];
    }
    
    return _clubView;
}
-(UILabel *)clubNumLabel{
    if (!_clubNumLabel) {
        _clubNumLabel = [[UILabel alloc] init];
        [_clubNumLabel  setText:@"俱乐部号"];
        [_clubNumLabel setTextColor:[UIColor blackColor]];
        [_clubNumLabel setFont:FONT(16)];
       
    }
    
    return _clubNumLabel;
}
-(UILabel *)clubNumber{
    if (!_clubNumber) {
        _clubNumber = [[UILabel alloc] init];
        [_clubNumber  setText:@"52877446"];
        [_clubNumber setTextColor:PQ_COLOR_SimpleGary];
        [_clubNumber setFont:FONT(14)];
    
    }
    
    return _clubNumber;
}
-(UILabel *)associatorLabel{
    if (!_associatorLabel) {
        
        _associatorLabel = [[UILabel alloc] init];
        _associatorLabel.backgroundColor = PQ_COLOR_LightGray;
        [_associatorLabel  setText:@"会员 12/100"];
        [_associatorLabel setTextColor:[UIColor blackColor]];
        [_associatorLabel setFont:FONT(16)];
        
    }
    
    return _associatorLabel;
}
-(UICollectionView *)associatorCollectionView{
    if (!_associatorCollectionView) {
        UICollectionViewFlowLayout *flowlayout = [[UICollectionViewFlowLayout alloc] init];
        _associatorCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowlayout];
        [flowlayout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
        _associatorCollectionView.backgroundColor = [UIColor whiteColor];
        flowlayout.itemSize = CGSizeMake(RATIO(100), RATIO(100));
        flowlayout.minimumLineSpacing =RATIO(30);
        flowlayout.sectionInset = UIEdgeInsetsMake(RATIO(22.5), RATIO(60), RATIO(22.5), RATIO(60));
        _associatorCollectionView.delegate = self;
        _associatorCollectionView.dataSource = self;
        //注册cell
        [_associatorCollectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:CellID];
        
        
    
    
    
    
}
    return _associatorCollectionView;
}

-(UIView *)aestivateView{
    if (!_aestivateView) {
        _aestivateView = [[UIView alloc] init];
        _aestivateView.backgroundColor = [UIColor whiteColor];
    }
    
    return _aestivateView;
}

-(UILabel *)aestivateLabel{
    if (!_aestivateLabel) {
        
        _aestivateLabel = [[UILabel alloc] init];
        _aestivateLabel.backgroundColor = [UIColor whiteColor];
        [_aestivateLabel  setText:@"消息免打扰"];
        [_aestivateLabel setTextColor:[UIColor blackColor]];
        [_aestivateLabel setFont:FONT(16)];
        
    }
    
    return _aestivateLabel;
}
-(UISwitch*)messageSwitch{
    if (!_messageSwitch) {
        _messageSwitch = [[UISwitch alloc] init];
        
    }
    
    return _messageSwitch;
}
-(UIView *)clearView{
    if (!_clearView) {
        _clearView = [[UIView alloc] init];
        _clearView.backgroundColor = [UIColor whiteColor];
    }
    
    return _clearView;
}
-(UILabel *)clearLabel{
    if (!_clearLabel) {
        
        _clearLabel = [[UILabel alloc] init];
        _clearLabel.backgroundColor = [UIColor whiteColor];
        [_clearLabel  setText:@"清除所有聊天记录"];
        [_clearLabel setTextColor:[UIColor blackColor]];
        [_clearLabel setFont:FONT(16)];
        
    }
    
    return _clearLabel;
}

-(UILabel *)buildDateLabel{
    if (!_buildDateLabel) {
        
        _buildDateLabel = [[UILabel alloc] init];
        _buildDateLabel.backgroundColor = PQ_COLOR_LightGray;
        [_buildDateLabel  setText:@"创建于 2016-03－02"];
        [_buildDateLabel setTextColor:PQ_COLOR_SimpleGary];
        [_buildDateLabel setFont:FONT(12)];
        _buildDateLabel.textAlignment = NSTextAlignmentCenter;
        
    }
    
    return _buildDateLabel;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
